package com.asia5b.a5mall.member.adapter

import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.asia5b.a5mall.member.R
import com.asia5b.a5mall.member.databinding.ItemPostcommentAdapterBinding
import com.asia5b.a5mall.member.widget.UploadView
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.utils.startGoodsDetailActivity
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class PostCommentAdapter(list: ArrayList<AbsGoodsModel>) :
        BaseQuickAdapter<AbsGoodsModel, BaseDataBindingHolder<ItemPostcommentAdapterBinding>>(R.layout.item_postcomment_adapter, list) {
    override fun convert(helper: BaseDataBindingHolder<ItemPostcommentAdapterBinding>, item: AbsGoodsModel) {
        val position = helper.layoutPosition
        val binding = helper.dataBinding!!
        binding.model = item

        val iv_postcomment_img = helper.getView<ImageView>(R.id.iv_postcomment_img)
        val ll_postcomment_haoping = helper.getView<LinearLayout>(R.id.ll_postcomment_haoping)
        val tv_postcomment_haoping = helper.getView<TextView>(R.id.tv_postcomment_haoping)
        val ll_postcomment_zhongping = helper.getView<LinearLayout>(R.id.ll_postcomment_zhongping)
        val tv_postcomment_zhongping = helper.getView<TextView>(R.id.tv_postcomment_zhongping)
        val ll_postcomment_chaping = helper.getView<LinearLayout>(R.id.ll_postcomment_chaping)
        val tv_postcomment_chaping = helper.getView<TextView>(R.id.tv_postcomment_chaping)
        val upload_postcomment = helper.getView<UploadView>(R.id.upload_postcomment)
        upload_postcomment.uploadPosition = position
        upload_postcomment.selectionMedia = item.selectionMedia

        val setGoodsStar = {
            tv_postcomment_haoping.isSelected = item.goodsStar == 5
            tv_postcomment_zhongping.isSelected = item.goodsStar == 3
            tv_postcomment_chaping.isSelected = item.goodsStar == 1
        }
        setGoodsStar.invoke()

        ll_postcomment_haoping.setOnClickListener {
            item.goodsStar = 5
            setGoodsStar.invoke()
        }
        ll_postcomment_zhongping.setOnClickListener {
            item.goodsStar = 3
            setGoodsStar.invoke()
        }
        ll_postcomment_chaping.setOnClickListener {
            item.goodsStar = 1
            setGoodsStar.invoke()
        }

        iv_postcomment_img.setOnClickListener {
            startGoodsDetailActivity(context,item.absGoodsId)
        }
    }
}